/**************************************************************************
 * Licensed Material - Property of ShangHai i2Finance.                    *
 * Copyright (c) ShangHai I2Finance Inc. 2009-2012-All rights reserved.   * 
 * (<http://www.i2finance.net>)                                           *
 *                                                                        *
 * This file contains proprietary intellectual property of                *
 * ShangHai i2Finance Inc. The contents of and information in this file   *
 * is only to be used in conjunction with a valid i2Shopping license      *
 * as specified in the  i2Shopping  license agreement. All other use      *
 * is prohibited.                                                         *
 **************************************************************************/
package com.TTBook.utils.keygen;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author Frank
 *
 * <b>Class Description:</b><br>
 * TODO Please add your class description here
 */
public class SerialGeneratorMgrAwareProcessor implements BeanPostProcessor,ApplicationContextAware{
    
    private ApplicationContext applicationContext;
    
    /* (non-Javadoc)
     * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String)
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof SerialGeneratorMgrAware) {
        	SerialGeneratorMgr keyGeneratorMgr = (SerialGeneratorMgr) this.applicationContext.getBean("serialGeneratorMgr");
            ((SerialGeneratorMgrAware) bean).setSerialGeneratorMgr(keyGeneratorMgr);
        }
        return bean;
    }

    /* (non-Javadoc)
     * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String)
     */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    /* (non-Javadoc)
     * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

}
